package com.seari.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
//@SpringBootConfiguration
public class MyWebAppConfiguration extends WebMvcConfigurerAdapter {
	

	@Override
	public void addCorsMappings(CorsRegistry registry) {
		// 允许所有跨域请求
		registry.addMapping("/**")
		.allowCredentials(true)
        .allowedHeaders("*")
        .allowedMethods("*")
        .allowedOrigins("*");;
	}

	/**
	 *  如果配置跨域，就增加这个配置
	 * @param registry
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/static/**").addResourceLocations("/static/");
		registry.addResourceHandler("/js/**").addResourceLocations("/js/");
		registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars");
	}
}